﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace OnlineCooperation
{
    /// <summary>
    /// PersonalFileDelFile 的摘要说明
    /// </summary>
    public class PersonalFileDelFile : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.Session["CurrentDir"] == null || context.Session["CurrentDir"].ToString() == "")
                return;

            String dir = context.Session["CurrentDir"].ToString();

            context.Response.ContentType = "text/plain";

            string file_name = context.Request["FileName"];

            string path = (dir + file_name);//必须在 文件夹 后边多加  / ,不然 获得的路径错误！！！

            if (System.IO.File.Exists(path))
            {
                // Use a try block to catch IOExceptions, to
                // handle the case of the file already being
                // opened by another process.
                try
                {
                    System.IO.File.Delete(path);

                    //context.Response.Write(path);
                }
                catch (System.IO.IOException e)
                {
                    context.Response.Write(e.Message);
                    return;
                }
            }
        }
           
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}